﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.ObjectModel
{

    /// <summary>
    /// Represents an optional method parameter.
    /// </summary>
    public class OptionalParameterDefinition : ParameterDefinition
    {
        private readonly ExpressionBase mDefaultValue;

        /// <summary>
        /// Initializes a new variant instance of the <see cref="OptionalParameterDefinition"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="defaultValue">The default value of the parameter.</param>
        public OptionalParameterDefinition(string name, ExpressionBase defaultValue) : this(name, defaultValue, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OptionalParameterDefinition"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="defaultValue">The default value of the parameter.</param>
        /// <param name="type">The type of the parameter.</param>
        public OptionalParameterDefinition(string name, ExpressionBase defaultValue, UnboundType type)
            : this(name, defaultValue, type, true, false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OptionalParameterDefinition"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="type">The type of the parameter.</param>
        /// <param name="defaultValue">The default value of the parameter.</param>
        /// <param name="isByRef">Whether the parameter is passed by reference or value.</param>
        /// <param name="isParamArray">Whether the parameter is a parameter array.</param>
        public OptionalParameterDefinition(string name, ExpressionBase defaultValue, UnboundType type, bool isByRef, bool isParamArray) :
            base (name, type, isByRef, isParamArray)
        {
            mDefaultValue = defaultValue;
        }

        /// <summary>
        /// Gets the expression which defines the default value of the parameter.
        /// </summary>
        public ExpressionBase DefaultValue
        {
            get { return mDefaultValue; }
        }
    }
}
